package com.example.logging.mq;

import com.example.logging.pojo.entity.OperationLogs;
import com.example.logging.service.IOperationLogsService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import static com.example.logging.constants.MQConstants.LOGGING_EXCHANGE;
import static com.example.logging.constants.MQConstants.LOGGING_RECEIVE_KEY;

@Component
@RequiredArgsConstructor
public class LogConsumer {
    private final IOperationLogsService operationLogsService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "operation.receive.queue", durable = "true"),
            exchange = @Exchange(name = LOGGING_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = LOGGING_RECEIVE_KEY
    ))
    public void listenUserOperations(OperationLogs operationLogs) {
        operationLogsService.save(operationLogs);
    }
}
